package cn.iocoder.yudao.module.voice.cc.config.interceptor;

import cn.iocoder.yudao.module.core.util.SnowflakeIdWorker;
import cn.iocoder.yudao.module.voice.cc.cache.CacheService;
import cn.iocoder.yudao.module.voice.cc.service.AgentService;
import io.minio.MinioClient;
import io.netty.util.HashedWheelTimer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.concurrent.TimeUnit;

/**
 * Create by caoliang on 2020/9/20implements WebMvcConfigurer
 */
@Configuration
public class WebConfig {

   /* @Autowired
    private AgentService agentService;

    @Autowired
    private CacheService cacheService;

    @Autowired
    private ApplicationContext applicationContext;*/

/*    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/cti/**")
                .allowCredentials(true)
                .allowedMethods("GET", "POST", "DELETE", "PUT", "PATCH")
                .maxAge(3600);*/
   // }

//    @Override
//    public void addInterceptors(InterceptorRegistry registry) {
//        registry.addInterceptor(new HttpRequestInteceptor(cacheService, applicationContext))
//                .addPathPatterns("/cti/call/**")
//                .addPathPatterns("/cti/agent/**")
//                .addPathPatterns("/cti/admin/**")
//                .excludePathPatterns("/cti/agent/login","/index/**", "/**/*.js", "/**/*.css", "/**/*.png");
//    }

    @Bean
    public SnowflakeIdWorker snowflakeIdWorker() {
        return new SnowflakeIdWorker(0, 0);
    }

    @Bean
    public HashedWheelTimer hashedWheelTimer() {
        return new HashedWheelTimer(100, TimeUnit.MILLISECONDS, 10240);
    }

    @Bean
    public MinioClient minioClient(@Value("${minio.endpoint:}") String endpoint, @Value("${minio.access.key:}") String accessKey, @Value("${minio.secret.key:}") String secretKey) {
        try {
            return new MinioClient.Builder().endpoint(endpoint).credentials(accessKey, secretKey).build();
        } catch (Exception e) {
//            logger.error(e.getMessage(), e);
        }
        return null;
    }
}
